[#ftl]
[#import "/projforge/engine/ftls/common/macrolibs.ftl" as lib]
[#import "/projforge/engine/ftls/common/commondb.ftl" as db]
CREATE TABLE `${db.myTableName}` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(128) NOT NULL,
  `description` varchar(256) DEFAULT NULL,
  `disabled` tinyint(1) DEFAULT NULL,[#if clazz.ownerLevel>0]
  `ownerid` int(10) unsigned COMMENT 'owner',[/#if][#if clazz.scopeClass??]
  `scopeid` int(10) unsigned COMMENT 'scope',[/#if][#list clazz.dynaAttributes as attr][#if !attr.carrier]
  `${db.myFieldNames["${attr.id}"]}` [@lib.dbFieldTypeMySQL attr=attr/][#if !attr.nullable] NOT NULL[/#if] COMMENT '${attr.name}',[/#if][/#list]
  PRIMARY KEY (`id`)[#if clazz.ownerLevel>0],
  KEY `FK_${db.myTableAlias}_owner_${db.myOwnerTableAlias}` (`ownerid`)[/#if][#if clazz.scopeClass??],
  KEY `FK_${db.myTableAlias}_scope_${db.myScopeTableAlias}` (`scopeid`)[/#if][#list 
                        clazz.dynaAttributes as attr][#if !attr.carrier&&attr.type>8],
  KEY `FK_${db.myTableAlias}_${db.myRefTableAlias["${attr.id}"]}` (`${db.myFieldNames["${attr.id}"]}`)[/#if][/#list][#if
                        clazz.ownerLevel>0],
  CONSTRAINT `FK_${db.myTableAlias}_owner_${db.myOwnerTableAlias}` FOREIGN KEY (`ownerid`) REFERENCES `${db.myOwnerTableName}` (`id`)[/#if][#if
                        clazz.scopeClass??],
  CONSTRAINT `FK_${db.myTableAlias}_scope_${db.myScopeTableAlias}` FOREIGN KEY (`scopeid`) REFERENCES `${db.myScopeTableName}` (`id`)[/#if][#list 
                        clazz.dynaAttributes as attr][#if !attr.carrier&&attr.type>8],
  CONSTRAINT `FK_${db.myTableAlias}_${db.myRefTableAlias["${attr.id}"]}` FOREIGN KEY (`${db.myFieldNames["${attr.id}"]}`) REFERENCES `${db.myRefTables["${attr.id}"]}` (`id`)[/#if][/#list]
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

